/* 短信发送
 * @Author: wujie 
 * @Date: 2018-06-12 11:06:22 
 * @Last Modified by: wujie
 * @Last Modified time: 2018-10-26 17:45:22
 */
import React, { Component } from 'react'
import components from '@/components'
import { connect } from 'react-redux'
import actions from '@/actions/send'
import util from '@/utils'
import BASE_URL from '../../config/url'

const { MessageSend, Card } = components

class Send extends Component {

  render() {

    const props = util.pick(this.props, [
      'phones',
      'fileData',
      'fileName',
      'signData',
      'sign',
      'phoneSelectTypes',
      'messageContent',
      'importButtonLoading',
      'signType',
      'isSendButtonLoading',
    ])

    const funcProps = util.pick(this, [
      'onChangePhones',
      'onChangeSign',
      'onChangePhoneSelectTypes',
      'onChangeMessageContent',
      'onSignFront',
      'onSignBack',
      'onSend',
      'customUploadRequest',
      'onTemplateDownload',
    ])

    return (
      <Card title="短信发送">
        <MessageSend {...props} {...funcProps} />
      </Card>
    )
  }

  componentDidMount() {
    this.props.getSignData()
  }

  onChangePhones = ({ target: { value }}) => {
    this.props.setPhones(value)
  }

  onChangeSign = (value) => {
    this.props.setSign(value)
  }

  onChangeMessageContent = ({ target: { value } }) => {
    this.props.setMessageContent(value)
  }

  onTemplateDownload = () => {
    window.open(`${BASE_URL}/sms/msgSend/downloadTemplate?fileName=phoneTemplate.csv`)
  }

  onSignFront = () => {
    this.props.setSignFront()
  }

  onSignBack = () => {
    this.props.setSignBack()
  }

  onSend = () => {
    this.props.send()
  }

  customUploadRequest = (data) => {
    this.props.importFile(data)
  }

  onChangePhoneSelectTypes = (value) => {
    console.log('va', value, this.props)
    this.props.changePhoneSelectTypes(value)
  }

}

const mapStateToProps = ({ sendReducer }) => ({ ...sendReducer })

const mapDispatchToProps = { ...actions }

export default connect(mapStateToProps, mapDispatchToProps)(Send)